﻿using System;
using System.Data;
using System.Collections.Generic;
using jnpic.Common;
using jnpic.Model;
namespace jnpic.BLL
{
    /// <summary>
    /// SysLog
    /// </summary>
    public partial class SysLog
    {
        private readonly jnpic.DAL.SysLog dal = new jnpic.DAL.SysLog();
        public SysLog()
        { }
        #region  Method
       
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(jnpic.Model.SysLog model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int LogID)
        {

            return dal.Delete(LogID);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string LogIDlist)
        {
            return dal.DeleteList(LogIDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public jnpic.Model.SysLog GetModel(int LogID)
        {

            return dal.GetModel(LogID);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public jnpic.Model.SysLog GetModelByCache(int LogID)
        {

            string CacheKey = "SysLogModel-" + LogID;
            object objModel = jnpic.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(LogID);
                    if (objModel != null)
                    {
                        int ModelCache = jnpic.Common.ConfigHelper.GetConfigInt("ModelCache");
                        jnpic.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (jnpic.Model.SysLog)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<jnpic.Model.SysLog> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<jnpic.Model.SysLog> DataTableToList(DataTable dt)
        {
            List<jnpic.Model.SysLog> modelList = new List<jnpic.Model.SysLog>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                jnpic.Model.SysLog model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new jnpic.Model.SysLog();
                    if (dt.Rows[n]["LogID"].ToString() != "")
                    {
                        model.LogID = int.Parse(dt.Rows[n]["LogID"].ToString());
                    }
                    model.IP = dt.Rows[n]["IP"].ToString();
                    model.Page = dt.Rows[n]["Page"].ToString();
                    model.Message = dt.Rows[n]["Message"].ToString();
                    if (dt.Rows[n]["AddTime"].ToString() != "")
                    {
                        model.AddTime = DateTime.Parse(dt.Rows[n]["AddTime"].ToString());
                    }
                    if (dt.Rows[n]["AddUserID"].ToString() != "")
                    {
                        model.AddUserID = int.Parse(dt.Rows[n]["AddUserID"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}

